﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using radDemo;

namespace RadDemo
{
    public class Query
    {
     public static  void Insert(int id,string area,string name,string logo,string product ,string wS)
       {
           var data = new roadmapEntities();
           /*
            * using object initalizer
            */
           var company = new Manufacture
               {
                manufacture_id = (byte)id,
                area_served = area,
                name = name,
                logo = logo,
                products = product,
                website = wS
               };
         data.AddToManufactures(company);
         data.SaveChanges();

       }
     public static void Insert()
     {
         var data = new roadmapEntities();
         /*
          * using object initalizer
          */
         var company = new Manufacture
         {
             manufacture_id = 4,
             area_served = "some thing",
             name = "some name",
             logo = "Images/heart.png",
             products = "laptop",
             website = "http://www.company.com"
         };
         data.AddToManufactures(company);
         data.SaveChanges();

     }
        public static void Insert2()
        {
            var data = new roadmapEntities();

            /*
             * using AddTo<name_of_tables>
             */ 
            var device = new Device();
            device.device_id = 3;
            device.name = "x302";
            device.code = "23edfwijdlwjc";
            device.cost = 1500;
            device.default_price = 1100;
            device.start_date = new DateTime(2013,3,1);
            device.end_date = new DateTime(2013,5,31);
            device.manufacture_id = 1;
            device.manufacturing_date = new DateTime(2011,9,20);
           
            data.AddToDevices(device);
            data.SaveChanges();
        }
        public static void Update(int id,decimal cost)
        {
            var data = new roadmapEntities();
            var device = new Device();
            var tmp = data.Devices.First(d => d.images_id == id);
            /*find the first element that meets the condition*/
            if(tmp!=null)
            tmp.cost = cost;
        }

        public static string Images(int id)
        {
            var data = new roadmapEntities();
            string path = "";
            var img = data.Manufactures.First(m => m.manufacture_id == id);
            /*find the first element thats meet the condition*/
            if(img!=null)
             path= img.logo;
            return path;
        }
        public static void Delete(int id)
        {
            var data = new roadmapEntities();
            var device = data.Devices.First(d => d.device_id == id);
            /*find the first element that meets the condition*/
            if(device !=null)
                data.Devices.DeleteObject(device);
        }
    }
}